package cn.com.cetccst.sdk.modelbase;


import static cn.com.cetccst.sdk.channel.SSAct.SS_SDK_VERSION;
import static cn.com.cetccst.sdk.modelbase.ConstantsAPI.COMMAND_UNKNOWN;
import static cn.com.cetccst.sdk.modelbase.ConstantsAPI.SSAPI_COMMAND_TYPE;

import android.os.Bundle;
import android.text.TextUtils;

import cn.com.cetccst.sdk.utils.SSAPIUtil;

public abstract class BaseReq {
    public static final String SSAPI_BASEREQ_TRANSACTION = "ssapi_basereq_transaction";
    public static final String SSAPI_BASEREQ_APPKEY = "ssapi_basereq_appkey";
    public int type = COMMAND_UNKNOWN;
    public String transaction;
    public int sdkVersion;
    public String appKey;

    public BaseReq(int type) {
        this.type = type;
        if (SSAPIUtil.isInitialised()) {
            //如果工具类已经初始化，就直接将transaction初始化一下(主要是为了H5，小程序的请求)
            transaction = SSAPIUtil.buildTransaction(getType());
        }
    }

    public int getType() {
        return type;
    }

    public void toBundle(Bundle bundle) {
        bundle.putInt(SSAPI_COMMAND_TYPE, getType());
        if (TextUtils.isEmpty(transaction)) {
            transaction = SSAPIUtil.buildTransaction(getType());
        }
        bundle.putString(SSAPI_BASEREQ_TRANSACTION, transaction);
        bundle.putString(SSAPI_BASEREQ_APPKEY, appKey);
    }

    public void fromBundle(Bundle bundle) {
        type = bundle.getInt(SSAPI_COMMAND_TYPE);
        transaction = bundle.getString(SSAPI_BASEREQ_TRANSACTION);
        appKey = bundle.getString(SSAPI_BASEREQ_APPKEY);
        sdkVersion = bundle.getInt(SS_SDK_VERSION);
    }

    public boolean checkArgs() {
        return true;
    }

    @Override
    public String toString() {
        return "BaseReq{" +
                "type=" + type +
                ", transaction='" + transaction + '\'' +
                '}';
    }
}
